# -*-coding:utf-8 -*-
from elecwater.models import *
import utils

def msgOrderInfo(aDevInfos,aDev_ok_status,aDev_use_status,aDev_value):
    #-- '水表编号,水表名称,mac地址,单价,备注,最低消费,计费方式,设备正常状态,设备使用状态,水表数'
    tmpMsg = {}
    tmpMsg["devid"]     = aDevInfos.split(";")[0]
    tmpMsg["devname"]   = aDevInfos.split(";")[1]
    tmpMsg["devmac"]    = aDevInfos.split(";")[2]
    tmpMsg["price"]     = aDevInfos.split(";")[3]
    tmpMsg["remark"]    = aDevInfos.split(";")[4]
    tmpMsg["mincharge"] = aDevInfos.split(";")[5]
    tmpMsg["type"]      = aDevInfos.split(";")[6]
    tmpMsg["dev_ok_status"]  = aDev_ok_status
    tmpMsg["dev_use_status"] = aDev_use_status
    tmpMsg["dev_value"]      = aDev_value
    print tmpMsg
    return tmpMsg
def msgAppCheck(aUid):
    tmpMsg = {}
    tmpMsg["status"] = 0
    tmpMsg["uid"] = aUid
    tmpMsg["msg"]    = "ok"
    print tmpMsg
    return tmpMsg

def msgOrder(aOrder):
    tmpMsg = {}
    tmpMsg['oid']    = "1243321"
    tmpMsg['devid']  = "123578765"
    tmpMsg['dname']  = utils.base64Encode("环球海洋批发市场0001")
    tmpMsg['stime']  = "2016-11-10 12:12:12"
    tmpMsg['etime']  = "2016-11-11 12:12:12"
    tmpMsg['evalue'] = 1.3
    tmpMsg['svalue'] = 3.3
    tmpMsg['eunit']  = 123.00
    tmpMsg['etotal'] = 123.33
    tmpMsg['eprint'] = 1
    tmpMsg['epstop'] = 1
    print tmpMsg
    return tmpMsg

def msgOrderList(aList):
    tmpMsg = {}
    tmpMsg["status"] = 0
    tmpMsg["infos"]  = []

    for i in aList:
        tmpMsg1 = {}
        str = i.split(";")
        if len(str) <= 10:
            continue
        try:
            tmpMsg1["marketname"]    = str[0]
            tmpMsg1["name"]          = str[1]
            tmpMsg1["card"]          = str[2]
            tmpMsg1["price_second"]  = str[3]
            tmpMsg1["price_tone"]    = str[4]  
            tmpMsg1["type"]          = str[5]  
            tmpMsg1["saleno"]        = str[6]    
            tmpMsg1["money"]         = str[7]    
            tmpMsg1["start_tones"]   = str[8]
            tmpMsg1["stop_tones"]    = str[9]
            tmpMsg1["tones"]         = str[10]    
            tmpMsg1["seconds"]       = str[11]    
            tmpMsg1["start_time"]    = str[12]    
            tmpMsg1["stop_time"]     = str[13]
            tmpMsg1["posid"]         = str[14]
            tmpMsg1["print_num"]     = str[15]
        except:
            print ""
        tmpMsg["infos"].append(tmpMsg1)
            
    #print tmpMsg
    return tmpMsg

def msgAppUser(aUser):
    tmpMsg = {}
    tmpMsg["status"] = 0
    tmpMsg["card"]  = aUser.split(";")[0]
    tmpMsg["phone"]  = aUser.split(";")[1]
    tmpMsg["ubala"]  = aUser.split(";")[2]
    tmpMsg["mname"]  = aUser.split(";")[3]
    print tmpMsg
    return tmpMsg


def msgOneDevStatus(aStr,status,aValue):
    tmpMsg = {}
    tmpMsg["status"] = 0
    tmpMsg["infos"]  = {}

    tmpMsg1 = {}
    tmpMsg1["dev_status"]    = status
    tmpMsg1["dev_value"]     = aValue
    str = aStr.split(";")
    tmpMsg1["posid"]         = str[0]    
    tmpMsg1["name"]          = str[1]    
    tmpMsg1["mac"]           = str[2]    
    tmpMsg1["price_second"]  = str[3]
    tmpMsg1["price_tone"]    = str[4]  
    tmpMsg1["type"]          = str[5]  
    tmpMsg1["start_seconds"] = str[6]    
    tmpMsg1["minCharge"]     = str[7]    
    tmpMsg1["balance"]       = str[8]
    #如果没有交易记录.下面信息不会显示
    if len(str) > 9:
        tmpMsg1["saleno"]        = str[9]    
        tmpMsg1["money"]         = str[10]    
        tmpMsg1["start_tones"]   = str[11]    
        tmpMsg1["stop_tones"]    = str[12]    
        tmpMsg1["tones"]         = str[13]  
        tmpMsg1["seconds"]       = str[14] 
        tmpMsg1["start_time"]    = str[15]
        tmpMsg1["stop_time"]     = str[16] 

    #tmpMsg["infos"].append(tmpMsg1)
    tmpMsg["infos"] = tmpMsg1
    #print tmpMsg
    return tmpMsg

def msgErr2(aErr, aMsg):
    tmpMsg = {}
    tmpMsg["status"] = aErr
    tmpMsg["msg"]    = utils.base64Encode(aMsg)
    print tmpMsg
    return tmpMsg

def msgOk():
    tmpMsg = {}
    tmpMsg["status"] = 0
    tmpMsg["msg"]    = "ok"
    print tmpMsg
    return tmpMsg
    
def msgOrderStart(aSaleno,aValue):
    tmpMsg = {}
    tmpMsg["stime"]  = utils.timeUnix()
    tmpMsg["svalue"] = aValue
    tmpMsg["saleno"] = aSaleno
    print tmpMsg
    return tmpMsg

def msgOrderStop(aValue):
    tmpMsg = {}
    tmpMsg["status"] = 0
    tmpMsg["value"]  = aValue
    print tmpMsg
    return tmpMsg
    
def msgUseingList(aArr):
    tmpMsg = {}
    tmpMsg["status"] = 0
    tmpMsg["infos"]  = []

    cishu = 0
    for i in aArr:
        tmpMsg1 = {}
        str = i.split(";")
        if len(str) <= 10:
            continue
        try:
            tmpMsg1["posid"]         = str[0]
            tmpMsg1["name"]          = str[1]
            tmpMsg1["mac"]           = str[2]
            tmpMsg1["price_second"]  = str[3]
            tmpMsg1["price_tone"]    = str[4]  
            tmpMsg1["type"]          = str[5]  
            tmpMsg1["start_seconds"] = str[6]    
            tmpMsg1["minCharge"]     = str[7]    
            tmpMsg1["balance"]       = str[8]
            tmpMsg1["saleno"]        = str[9]
            tmpMsg1["money"]         = str[10]    
            tmpMsg1["start_tones"]   = str[11]    
            tmpMsg1["stop_tones"]    = str[12]    
            tmpMsg1["tones"]         = str[13]  
            tmpMsg1["seconds"]       = str[14] 
            tmpMsg1["start_time"]    = str[15]
            tmpMsg1["stop_time"]     = str[16] 
        except:
            print ""
        tmpMsg["infos"].append(tmpMsg1)
            
    #print tmpMsg
    return tmpMsg
